1 import java.io.*;
2
3
11
12 public class Syotto {
13
19 public static int kysy_int(String kysymys, int oletus)
20 {
21 BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
22 while ( true ) {
23 System.out.print(kysymys+" >");
24 String s = "";
25 try {
26 s = in.readLine();
27 } catch (IOException ex) {
28 continue;
29 }
30 if ( ( s == null ) || ( s.equals("") ) ) return oletus;
31 try {
32 return Integer.parseInt(s);
33 } catch (NumberFormatException ex) {
34 System.out.println("Ei numero: " + s);
35 }
36 }
37 }
38
39 public static void main(String[] args) {
40 int i;
41 i = kysy_int("Anna kokonaisluku",12);
42 System.out.println("Luku oli: " + i);
43 }
44 }